import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';

import { NzModalService } from 'ng-zorro-antd/modal';

/**
 * 提示框
 */
@Injectable({ providedIn: 'root' })
export class TipsModalService {
  constructor(private modalSrc: NzModalService) {}

  info<T>(content: string): Subject<T> {
    return this.common('信息提示', content, 'info');
  }

  warning<T>(content: string): Subject<T> {
    return this.common('警告提示', content, 'warning');
  }

  success<T>(content: string): Subject<T> {
    return this.common('成功提示', content, 'success');
  }

  fail<T>(content: string): Subject<T> {
    return this.common('失败提示', content, 'error');
  }

  private common<T>(title: string, content: string, type: string): Subject<T> {
    // @ts-ignore
    const modal = this.modalSrc[type]({
      nzTitle: title,
      nzContent: content
    });

    return modal.afterClose;
  }
}
